#!/bin/sh
# $Id: rc.redhat.asterisk 226811 2009-11-02 17:14:20Z tilghman $
#
# callgend	   Starts, Stops and Reloads Asterisk.
#
# chkconfig: 2345 92 64
# description: callgen daemon start-stop script 
# processname: callgen
# pidfile: /var/run/callgen.pid
#
# We Sep 22 2010 
# Version 1.0

# Installation directory
DAEMON_DIR=/usr/local/bin

# Source function library.
. /etc/rc.d/init.d/functions

if ! [ -x $DAEMON_DIR/callgen ] ; then
	echo "ERROR: $DAEMON_DIR/callgen not found"
	exit 0
fi



# Full path to daemon
PROG=callgen
DAEMON=$DAEMON_DIR/$PROG
DAEMONARGS='-v -d &> /dev/null'
PIDFILE=/var/run/$PROG.pid


# Allow configuration overrides in /etc/sysconfig/callgen
CONFIG0=`readlink $0`
if [ "$CONFIG0" = "" ]; then
	CONFIGFILE=/etc/sysconfig/`basename $0`
else
	CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
fi
[ -x $CONFIGFILE ] && . $CONFIGFILE

RETVAL=0

start() {

	if status $PROG > /dev/null; then
		status $PROG
		exit 1
	fi

	# Start daemons.
	echo -n $"Starting callgen: "
   	daemon $DAEMON $DAEMONARGS 
 
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$PROG && 
	pidofproc $PROG > $PIDFILE
	echo
	return $RETVAL
}

stop() {
	# Stop daemons.
	echo -n $"Shutting down callgen: "
	killproc `basename $DAEMON`
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROG
	echo
	return $RETVAL
}

restart() {
	stop
	start
}


# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  condrestart)
	[ -f /var/lock/subsys/$PROG ] && restart || :
	;;
  status)
	status callgen
	;;
  *)
	echo "Usage: callgen {start|stop|restart|reload|condrestart|status}"
	exit 1
esac

exit $?
